//
//  HWGameDetailHttpManager.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/10.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit
import Alamofire
class HWGameDetailHttpManager: NSObject {
    var uid = HWLocallyStoredData.getLoginUserID()
    var tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
    var p = 1
    var max_p = "1"
}

extension HWGameDetailHttpManager {
    /// sign加密
    /// - Returns: sign
    func encrySign() -> String {
        
        let sign = "\(uid)\(tStr)\("fsd213ewdsadqwe2121213edsad")"
        let signMD5 = WMUtil.md5HexDigest(sign) ?? ""
        return signMD5
    }
    func headers() -> HTTPHeaders {
        //        let tStr = Date().timeStamp
        //        let signature = "nnmitu"+tStr
        //
        //        let json = ["usersid":HWLocallyData.getUsersID(),"timestamp":tStr,"signature":signature.DDMD5Encrypt(.lowercase32)]
        //        let jsonString = HWPublicFuncTools.convertDictionAryToJson(dic: json as NSDictionary)
        //        let aesStr:String = aesEncryptString(jsonString, "NrrynIXcpucYvGSk")
        let header:HTTPHeaders = ["eaua":JJUUIDManager.getUUID(),"imei":ASIdentifierManager.shared().advertisingIdentifier.uuidString]
        
        return header
    }
}
extension HWGameDetailHttpManager {
    
    /// 游戏详情
    func getGameDetailTop(gameId:String,success:@escaping (_ model:HWGameDetailModel) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailTop)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameDetailModel.deserialize(from: result ,designatedPath: "") {
                            print(model)
                            success(model)
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    ///获取游戏详情标签列表
    func getGameDetailTagList(gameId:String,success:@escaping (_ models:[HWGameDetailTagModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "gid":gameId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailTag)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailTagModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailTagModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    /// 获取游戏详情群组信息
    func getGameDetailGroupInfo(gameId:String,success:@escaping (_ model:HWGameDetailGroupInfoModel) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "id":gameId,
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailGroup)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameDetailGroupInfoModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    /// 游戏详情下部分
    func getGameDetailInfo(gameId:String,success:@escaping (_ model:HWGameDetailInfoModel) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailInfo)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameDetailInfoModel.deserialize(from: result ,designatedPath: "") {
                            print(model)
                            success(model)
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 详情评论列表
    func getGameDetailCommentList(gameId:String, _ page: Int = 1,success:@escaping (_ models:[HWGameDetailCommentListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "p":page
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailCommentList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailCommentListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailCommentListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 详情评论点赞
    func getGameDetailCommentZan(id:String,success:@escaping (_ success:Bool) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailCommentZan)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 游戏收藏
    /// type:0游戏  1积分商城  2交易
    func setGameDetailCollection(id:String,type:String,success:@escaping (_ success:Bool) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "ios":"1",
            "type":type,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailCollection)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 取消游戏收藏
    func setGameDetailCollectionDel(id:String,type:String,success:@escaping (_ success:Bool) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "ios":"1",
            "type":type,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailCollectionDel)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 获取子评论
    func getGameCommentSonList(pid:String,success:@escaping (_ models:[HWGameDetailCommentListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "pid":pid,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCommentSonList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailCommentListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailCommentListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 发表评论
    func sendGameComment(gameId:String,content:String,pid:String,ppid:String,success:@escaping (_ success:Bool) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "id":gameId,
            "content":content,
            "pid":pid,
            "ppid":ppid,
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_SendComment)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 获取游戏详情开服表
    func getGameDetailOpenServiceList(gameId:String,success:@escaping (_ models:[HWGameDetailOpenServiceModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "p":p,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailOpenService)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailOpenServiceModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailOpenServiceModel])
                            
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 获取游戏详情开服表
    func getGameDetailOpenServiceListFooter(gameId:String,success:@escaping (_ models:[HWGameDetailOpenServiceModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "p":p,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailOpenService)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailOpenServiceModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailOpenServiceModel])
                            
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        self.p -= 1
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        self.p -= 1
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    self.p -= 1
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                self.p -= 1
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 获取游戏详情交易
    func getGameDetailTradeList(gameId:String,success:@escaping (_ models:[HWGameDetailTradeModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "p":p,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailTrade)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailTradeModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailTradeModel])
                            
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 获取游戏详情交易
    func getGameDetailTradeListFooter(gameId:String,success:@escaping (_ models:[HWGameDetailTradeModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":gameId,
            "p":p,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameDetailTrade)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameDetailTradeModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameDetailTradeModel])
                            
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        self.p -= 1
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        self.p -= 1
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    self.p -= 1
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                self.p -= 1
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 发布游戏评价
    func setCommentRelease(para:NSMutableDictionary,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        para.setValue(uid, forKey: "uid")
        para.setValue(tStr, forKey: "t")
        para.setValue(encrySign(), forKey: "sign")
        
        AF.request(URL(string: URL_SendComment)!, method: .get, parameters: para as? Parameters).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
                    //                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
                
            }
        }
    }
}
